package com.imau.service;

import com.imau.bean.Student;
import com.imau.bean.PageEntitry;
import com.imau.bean.User;
import com.imau.mapper.StudentMapper;
import com.imau.common.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class StudentServiceImpl {

    private SqlSession sqlSession;

    private StudentMapper studentMapper;

    public StudentServiceImpl() {
        sqlSession = SqlSessionUtil.getSqlSession();
        studentMapper = sqlSession.getMapper(StudentMapper.class);
    }

    public List<Student> selectAll() {
        List<Student> students = studentMapper.studentList();
        return students;
    }

    public PageEntitry<Student> selectPageByCondition(Integer currentPage, Integer pageSize, Student student) {
        //1.创建Page对象
        PageEntitry<Student> pageEntitry = new PageEntitry<>();
        //3.查询记录
        List<Student> students = studentMapper.selectPageByCondition((currentPage - 1) * pageSize, pageSize,student);
        //4.设置page属性
        pageEntitry.setCurrentPage(currentPage);
        pageEntitry.setPageSize(pageSize);
        pageEntitry.setRows(students);
        return pageEntitry;
    }
}


